package data;

import java.util.ArrayList;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;
import data.vectors.DoubleVectorIterator;
import data.vectors.implementation.DoubleVector_Sparse_Memory;

public class Filtering {
	public static void filter(DoubleVector_Sparse_Memory w, 
			OfflineSet<DoubleVector_Sparse_Memory> bd){
		OfflineSetIterator<DoubleVector_Sparse_Memory> bdIter = bd.inputsetiterator();
		while(bdIter.hasNext()){
			bdIter.next();
			DoubleVector_Sparse_Memory instance = bdIter.getCurrentObject();
			DoubleVectorIterator vecIter = instance.getNonNullIterator();
			ArrayList<Integer> list = new ArrayList<Integer>();
			while(vecIter.hasNext()){
				vecIter.next();
				int featureId = vecIter.getCurrentFeature();
				if (w.getValue(featureId)==0){
					list.add(featureId);
				}
			}
			for(Integer i: list){
				instance.setValue(i, 0);
			}
		}
	}
}
